package com.cat.dataStructure02;

import java.util.HashMap;
import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/brick-wall/description/
 * @create 2025/10/21 20:55
 * @since JDK17
 */

public class Solution40 {
    public int leastBricks(List<List<Integer>> wall) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (var row : wall) {
            int c = 0;
            for (int i = 0; i < row.size() - 1; i++) {
                c += row.get(i);
                map.merge(c, 1, Integer::sum);
            }
        }
        int ans = 0;
        for (var e : map.values()) {
            ans = Math.max(e, ans);
        }

        return wall.size() - ans;
    }
}
